﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Data.Converters;

namespace AvaloniaNotes.Converter
{
    internal class TextIndentConverter : IValueConverter
    {
        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            if (parameter is null)
            {
                return value;
            }
            if (value is string text && int.TryParse(parameter.ToString(), out var indent))
            {
                // 缩进是通过在文本前添加空格来实现的  
                return new string(' ', indent) + text;
            }
            return value;
        }

        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
